package ar.com.drconta.ganancias.views.code;

import java.util.ArrayList;

import java.util.List;
 

 
public class GameWorld {
 
        private static final int POPULATION = 11;
 
        private static GameWorld instance = new GameWorld();
 
        private GameWorld() {
 
        }
 
        public static GameWorld getInstance() {
 
                return instance;
 
        }
 
        private List<Team> allTeam = new ArrayList<Team>();
 
        public List<Team> getAllTeam() {
 
                return allTeam;
 
        }
 
        public boolean addTeam(Team team) {
 
                boolean addSuccess = false;
 
                if(null == team) return addSuccess;
 
                allTeam.add(team);
 
                addSuccess = true;
 
                return addSuccess;
 
        }
 
        
 
        public void initWorld() {
 
                Team t = new Team();
 
                instance.addTeam(t);
 
                for (int i = 0; i < POPULATION; i++) {
 
                        Person p = new Person();
 
                        p.setId(i);
 
                        p.setName(Person.getRandomName() + i);
 
                        boolean addMember = t.addMember(p);
 
                        if(!addMember) {
 
                                t = null;
 
                                t = new Team();
 
                                t.addMember(p);
 
                                instance.addTeam(t);
 
                        }
 
                }
 
        }
 
        
 
        public static void main(String[] args) {
 
                GameWorld.getInstance().initWorld();
 
                List<Team> allTeam = GameWorld.getInstance().getAllTeam();
 
                for (Team team : allTeam) {
 
                        Person[] allMember = team.getAllMember();
 
                        System.out.println(allMember.length);
 
                        for (Person p : allMember) {
 
                                if(null != p) {
 
                                        System.out.println(p.getId() + ":" + p.getName());
 
                                }
 
                        }
 
                }
 
        }
 
}
 
